package com.hsnn.medstgmini.base.std.dao.impl;
/**
 *  专家维护记录库
 */
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;





import com.hsnn.medstgmini.base.dict.dao.impl.BaseHibernateDAO;
import com.hsnn.medstgmini.base.std.dao.StdExpertLogDao;
import com.hsnn.medstgmini.base.std.model.StdExpertLog;
import com.hsnn.medstgmini.model.Result;

@Repository("stdExpertLogDao")
public class StdExpertLogDaoImpl extends  BaseHibernateDAO implements StdExpertLogDao{

	

	@SuppressWarnings("unchecked")
	@Override
	public List<StdExpertLog> SelectStdExpertLogList(Result result,StdExpertLog stdExpertLog) {
		String Name = stdExpertLog.getName();
		String ExpSkills = stdExpertLog.getExpSkills();
		String CompanyId = stdExpertLog.getCompanyId();
		
		StringBuffer hql = new StringBuffer();
		hql.append(" from StdExpertLog where 1 = 1 ");
		if(null != Name && !("").equals(Name)){
		hql.append(" and name like ?");
		}else if(null != ExpSkills && !("").equals(ExpSkills)){
			hql.append(" and exp_skills like ? ");
		}else if(null != CompanyId && !("").equals(CompanyId)){
			hql.append(" and company_id like ? ");
		}else if(null != Name && !("").equals(Name) && (null != ExpSkills && !("").equals(ExpSkills))&& (null != CompanyId && !("").equals(CompanyId)) ){
			hql.append(" and name like ? and exp_skills like ? and company_id like ? ");
		}
		Query query = getSession().createQuery(hql.toString());
		
		if(null != Name && !("").equals(Name)){
			query.setParameter(0, "%"+Name+"%");
			}else if(null != ExpSkills && !("").equals(ExpSkills)){
				query.setParameter(0, "%"+ExpSkills+"%");
			}else if(null != CompanyId && !("").equals(CompanyId)){
				query.setParameter(0, "%"+CompanyId+"%");	
			}else if(null != Name && !("").equals(Name) && (null != ExpSkills && !("").equals(ExpSkills)) && (null != CompanyId && !("").equals(CompanyId)) ){
				query.setParameter(0, "%"+Name+"%");
				query.setParameter(1, "%"+ExpSkills+"%");
				query.setParameter(2, "%"+ExpSkills+"%");
			}
		query.setFirstResult(result.getStart());
		query.setMaxResults(result.getPagesize());
		return query.list();
	}

	
}

